#include <map>

#include <atleast.h>
#include <utility.h>

typedef std::map<int, Uint64> TimingMap;

static TimingMap _tm;

bool atleast_do(int id, int ticks)
{
    TimingMap::iterator it = _tm.find(id);

    Uint64 now, dt;

    now = get_ticks();

    if (it == _tm.end()) {
        _tm.insert(TimingMap::value_type(id, now));
        return true;
    }

    dt = now - it->second;

    if (dt >= (Uint64) ticks) {
        it->second = now;
        return true;
    }

    return false;
}
